const userModule = {
  namespaced: true,
  state () {
    return {
      token: window.localStorage.getItem('token'),
      refreshToken: window.localStorage.getItem('refreshToken'),
      userInfo: {
        photo: window.localStorage.getItem('photo')
      }
    }
  },
  mutations: {
    setUserInfo (state, userObj) {
      // 对象合并，最好不要直接赋值
      state.userInfo = {
        ...state.userInfo,
        ...userObj
      }
      window.localStorage.setItem('photo', userObj.photo)
    },
    setToken (state, tokenStr) {
      state.token = tokenStr
      window.localStorage.setItem('token', tokenStr)
    },
    setRefreshToken (state, refreshTokenStr) {
      state.refreshToken = refreshTokenStr
      window.localStorage.setItem('refreshToken', refreshTokenStr)
    }
  }
}
export default userModule
